package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.DictBizEntity;
import com.uchiha.nova.core.model.vo.DictBizVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IDictBizService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 业务字典 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class DictBizWrapper extends BaseEntityWrapper<DictBizEntity, DictBizVO>  {
  
  IDictBizService dictBizService = SpringUtil.getBean(IDictBizService.class);
  
	public static DictBizWrapper build() {
		return new DictBizWrapper();
 	}

	@Override
	public DictBizVO entityVO(DictBizEntity dictBizEntity) {
		DictBizVO dictBizVO = new DictBizVO();
		BeanUtil.copyProperties(dictBizEntity, dictBizVO);

		return dictBizVO;
	}
	public List<DictBizVO> listVO(List<DictBizEntity> list) {
		List<DictBizVO> collect = list.stream().map(item -> {
            DictBizVO dictBizVO = new DictBizVO();
		    BeanUtil.copyProperties(item, dictBizVO);			
			return dictBizVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<DictBizVO> pageVO(IPage<DictBizEntity> pages) {
		IPage<DictBizVO> page = pages.convert(item->{
            DictBizVO dictBizVO = new DictBizVO();
		    BeanUtil.copyProperties(item, dictBizVO);			
			return dictBizVO;
		});
		return page;
	}
}
